Skip to content

/doc/core/: document zend_string APIs - #21642

Open
LamentXU123 wants to merge 1 commit into
php:masterfrom
LamentXU123:doc-1
Open

LamentXU123 wants to merge 1 commit into
php:masterfrom
LamentXU123:doc-1

Conversation

@LamentXU123

@LamentXU123 LamentXU123 commented Apr 5, 2026 •

Copy link
Copy Markdown
Member

This PR added (and also fixed) some internal APIs concerning zend_string, cc @iluuu1994 as we privately talk about the doc work before.

@LamentXU123 LamentXU123 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just commenting for easier reviewing

- - Function/Macro [#persistent]_
- Description

- - ``ZSTR_INIT(s, p)``

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original doc is wrong. This should be ZSTR_INIT_LITERAL. Is it?

- Same as ``zend_string_concat2``, but for three character buffers.

- - ``ZSTR_EMPTY_ALLOC()``
- Gets an immutable, empty string. This does not allocate memory.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return would be better in case of Get in functions

- Decreases the reference count and frees the string if it goes to 0.

- - ``zend_string_dup(s, p)``
- Creates a true copy of the string in a new allocation, except if the string is interned.

@LamentXU123 LamentXU123 Apr 5, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this function related to reference counting? Shouldn't it be in the "create/allocate" section?


- - ``ZSTR_HASH``
- ``Z_STRHASH[_P]``
- Computes the string has if it hasn't already been, and returns it.

@LamentXU123 LamentXU123 Apr 5, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this fix is right, but the original one is wrong.

API
*****

The string API is defined in ``Zend/zend_string.h``. It provides a number of functions for creating

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It do provide other functions except just for creating new strings?

hashing, and interning helpers.

.. list-table:: ``zend_string`` creation
.. list-table:: Creation and allocation APIs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make things more accurate here

Comment thread docs/source/core/data-structures/zend_string.rst

@iluuu1994 iluuu1994 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I wonder of how much use listing all functions and macros is. I think the docs should mainly focus on explaining concepts and core functions. Once you grasp that, you'll understand all the variations.

If we want to document these functions, maybe we should see if we can document them in-source instead and export the synopses somehow?

Anyway, I don't object but I think the wording could be improved.

Also: Yes, I started reviewing this in April. 😄

Comment thread docs/source/core/data-structures/zend_string.rst Outdated
Comment thread docs/source/core/data-structures/zend_string.rst Outdated
Comment thread docs/source/core/data-structures/zend_string.rst Outdated
Comment thread docs/source/core/data-structures/zend_string.rst Outdated
Comment thread docs/source/core/data-structures/zend_string.rst Outdated
Comment thread docs/source/core/data-structures/zend_string.rst Outdated
Comment thread docs/source/core/data-structures/zend_string.rst Outdated
Comment thread docs/source/core/data-structures/zend_string.rst Outdated
Comment thread docs/source/core/data-structures/zend_string.rst Outdated
Comment thread docs/source/core/data-structures/zend_string.rst Outdated
@LamentXU123

Copy link
Copy Markdown
Member Author

Thanks for reviewing! I am far from a native English user so yeah some wording might be bad.

@LamentXU123
LamentXU123 force-pushed the doc-1 branch 2 times, most recently from 524a1b3 to a364b50 Compare September 21, 2026 10:20
Co-authored-by: Ilija Tovilo <1752683+iluuu1994@users.noreply.github.com>
@LamentXU123

Copy link
Copy Markdown
Member Author

Hey @iliaal Can you give a quick review to the doc I wrote in this PR?
Also, I'd like to work on internal doc as much as I can, however I dont think I have enough time on it... While I agree we should more focus on documenting the core concepts itself, but I hope we can find some new contributors for that (perhaps a good first issue?)
Focusing on the PR itself, I think its ready to go.

@iluuu1994

Copy link
Copy Markdown
Member

Honestly, I wonder of how much use listing all functions and macros is. I think the docs should mainly focus on explaining concepts and core functions. Once you grasp that, you'll understand all the variations.

If we want to document these functions, maybe we should see if we can document them in-source instead and export the synopses somehow?

I think these are the main questions to answer here.

@LamentXU123

LamentXU123 commented Oct 18, 2026 •

Copy link
Copy Markdown
Member Author

Honestly, I wonder of how much use listing all functions and macros is. I think the docs should mainly focus on explaining concepts and core functions. Once you grasp that, you'll understand all the variations.

I see that in the opposite way. The reason I am writing these doc is to ideally document all useful functions. There are a lot of helpful sources out side (e.g. thephpinternalsbook) to get people learn what the core concepts and function is, however when implementating stuff, there are very little documentation about how other "variations" that might be useful work.

The motivation is when I start to contribute to php core, I start from reading books explaining PHP 8's internal concepts and referring to thephpinternalsbook all the time. However when actually writing PRs, I find it difficult to use the already existed APIs (like zend_string APIs) which is mostly undocumented or ill-documented.

If we want to document these functions, maybe we should see if we can document them in-source instead and export the synopses somehow?

Yes. But that's another topic I guess. I am all for "inlining" the documentation but I think this is more like a future scope and needs more discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants